<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- 
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License. 
-->
<html>
<head>
    <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css">
    <style type="text/css">
        .dp-highlighter {
            width:95% !important;
        }
    </style>
    <style type="text/css">
        .footer {
            background-image:      url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif');
            background-repeat:     repeat-x;
            background-position:   left top;
            padding-top:           4px;
            color:                 #666;
        }
    </style>
    <script type="text/javascript" language="javascript">
        var hide = null;
        var show = null;
        var children = null;

        function init() {
            /* Search form initialization */
            var form = document.forms['search'];
            if (form != null) {
                form.elements['domains'].value = location.hostname;
                form.elements['sitesearch'].value = location.hostname;
            }

            /* Children initialization */
            hide = document.getElementById('hide');
            show = document.getElementById('show');
            children = document.all != null ?
                    document.all['children'] :
                    document.getElementById('children');
            if (children != null) {
                children.style.display = 'none';
                show.style.display = 'inline';
                hide.style.display = 'none';
            }
        }

        function showChildren() {
            children.style.display = 'block';
            show.style.display = 'none';
            hide.style.display = 'inline';
        }

        function hideChildren() {
            children.style.display = 'none';
            show.style.display = 'inline';
            hide.style.display = 'none';
        }
    </script>
    <title>Comparing Struts 1 and 2</title>
</head>
<body onload="init()">
<table border="0" cellpadding="2" cellspacing="0" width="100%">
    <tr class="topBar">
        <td align="left" valign="middle" class="topBarDiv" align="left" nowrap>
            &nbsp;<a href="home.html">Home</a>&nbsp;&gt;&nbsp;<a href="guides.html">Guides</a>&nbsp;&gt;&nbsp;<a href="migration-guide.html">Migration Guide</a>&nbsp;&gt;&nbsp;<a href="comparing-struts-1-and-2.html">Comparing Struts 1 and 2</a>
        </td>
        <td align="right" valign="middle" nowrap>
            <form name="search" action="https://www.google.com/search" method="get">
                <input type="hidden" name="ie" value="UTF-8" />
                <input type="hidden" name="oe" value="UTF-8" />
                <input type="hidden" name="domains" value="" />
                <input type="hidden" name="sitesearch" value="" />
                <input type="text" name="q" maxlength="255" value="" />
                <input type="submit" name="btnG" value="Google Search" />
            </form>
        </td>
    </tr>
</table>

<div id="PageContent">
    <div class="pageheader" style="padding: 6px 0px 0px 0px;">
        <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
        <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
        <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div>
        <div style="margin: 0px 10px 8px 10px"  class="pagetitle">Comparing Struts 1 and 2</div>

        <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14048">
                <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14048">Edit Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">
                <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a>
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14048">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14048">Add Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14048">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add News"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14048">Add News</a>
        </div>
    </div>

    <div class="pagecontent">
        <div class="wiki-content">
            <div id="ConfluenceContent"><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Feature </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Struts 1 </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Struts 2 </p></th></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Action classes </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 1 requires Action classes to extend an abstract base class. A common problem in Struts 1 is programming to abstract classes instead of interfaces. </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> An Struts 2 Action <em>may</em> implement an <code>Action</code> interface, along with other interfaces to enable optional and custom services. Struts 2 provides a base ActionSupport class to implement commonly used interfaces. Albeit, the Action interface is <strong>not</strong> required. Any POJO object with a <code>execute</code> signature can be used as an Struts 2 Action object. </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Threading Model </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 1 Actions are singletons and must be thread-safe since there will only be one instance of a class to handle all requests for that Action. The singleton strategy places restrictions on what can be done with Struts 1 Actions and requires extra care to develop. Action resources must be thread-safe or synchronized. </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 2 Action objects are instantiated for each request, so there are no thread-safety issues. (In practice, servlet containers generate many throw-away objects per request, and one more object does not impose a performance penalty or impact garbage collection.) </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Servlet Dependency </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 1 Actions have dependencies on the servlet API since the HttpServletRequest and HttpServletResponse is passed to the <code>execute</code> method when an Action is invoked. </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 2 Actions are not coupled to a container. Most often the servlet contexts are represented as simple Maps, allowing Actions to be tested in isolation. Struts 2 Actions can still access the original request and response, if required. However, other architectural elements reduce or eliminate the need to access the HttpServetRequest or HttpServletResponse directly. </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Testability </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> A major hurdle to testing Struts 1 Actions is that the <code>execute</code> method exposes the Servlet API. A third-party extension, Struts TestCase, offers a set of mock object for Struts 1. </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 2 Actions can be tested by instantiating the Action, setting properties, and invoking methods. Dependency Injection support also makes testing simpler. </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Harvesting Input </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 1 uses an ActionForm object to capture input. Like Actions, all ActionForms must extend a base class. Since&#160; other JavaBeans cannot be used as ActionForms, developers often create redundant classes to capture input. DynaBeans can used as an alternative to creating conventional ActionForm classes, but, here too, developers may be redescribing existing JavaBeans. <br clear="none" class="atl-forced-newline"> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 2 uses Action properties as input properties, eliminating the need for a second input object. Input properties may be rich object types which may have their own properties. The Action properties can be accessed from the web page via the taglibs. Struts 2 also supports the ActionForm pattern, as well as POJO form objects and POJO Actions. Rich object types, including business or domain objects, can be used as input/output objects. The ModelDriven feature simplifies taglb references to POJO input objects. <br clear="none" class="atl-forced-newline"> </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Expression Language </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 1 integrates with JSTL, so it uses the JSTL EL. The EL has basic object graph traversal, but relatively weak collection and indexed property support. </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 2 can use JSTL, but the framework also supports a more powerful and flexible expression language called "Object Graph Notation Language" (OGNL). </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Binding values into views </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 1 uses the standard JSP mechanism for binding objects into the page context for access. </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 2 uses a "ValueStack" technology so that the taglibs can access values without coupling your view to the object type it is rendering. The ValueStack strategy allows reuse of views across a range of types which may have the same property name but different property types. <br clear="none" class="atl-forced-newline"> </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Type Conversion </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 1 ActionForm properties are usually all Strings. Struts 1 uses Commons-Beanutils for type conversion. Converters are per-class, and not configurable per instance. </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 2 uses OGNL for type conversion. The framework includes converters for basic and common object types and primitives. </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Validation </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 1 supports manual validation via a <code>validate</code> method on the ActionForm, or through an extension to the Commons Validator. Classes can have different validation contexts for the same class, but cannot chain to validations on sub-objects. </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 2 supports manual validation via the <code>validate</code> method and the XWork Validation framework. The Xwork Validation Framework supports chaining validation into sub-properties using the validations defined for the properties class type and the validation context. </p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Control Of Action Execution </p></th><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 1 supports separate Request Processors (lifecycles) for each module, but all the Actions in the module must share the same lifecycle. </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Struts 2 supports creating different lifecycles on a per Action basis via Interceptor Stacks. Custom stacks can be created and used with different Actions, as needed. </p></td></tr></tbody></table></div>


<div class="confluence-information-macro confluence-information-macro-information"><p class="title">See Also</p><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body">
<ul><li>Matt Raible wrote (mid 2005) an interesting whitepaper where he compared various web frameworks. You can view the PDF here:
	<ul><li><a shape="rect" class="external-link" href="https://equinox.dev.java.net/framework-comparison/WebFrameworks.pdf" rel="nofollow">https://equinox.dev.java.net/framework-comparison/WebFrameworks.pdf</a></li><li><a shape="rect" class="external-link" href="http://www.virtuas.com/files/osl-jwf-01.pdf" rel="nofollow">http://www.virtuas.com/files/osl-jwf-01.pdf</a></li></ul>
	</li></ul>
</div></div>

<h2 id="ComparingStruts1and2-Next:">Next: <a shape="rect" href="migration-strategies.html">Migration Strategies</a></h2></div>
        </div>

        
    </div>
</div>
<div class="footer">
    Generated by CXF SiteExporter
</div>
</body>
</html>
